import Common from '../../common/common.js';
import {LoginWin,EditMyWin} from './MenuWin.js';
import Friend from "../friend/Friend.js";



const doms ={
    userAvatar:Common.tool.getElementByID("userAvatar"),
    conversationMenu :Common.tool.getElementByID("conversationMenu"),
    groupMenu :Common.tool.getElementByID("groupMenu"),
    friendMenu :Common.tool.getElementByID("friendMenu"),
    blacklistMenu:Common.tool.getElementByID("blacklistMenu"),
    blacklistArea:Common.tool.getElementByID("blacklistArea"),
    conversationArea:Common.tool.getElementByID("conversationArea"),
    groupArea:Common.tool.getElementByID("groupArea"),
    friendArea:Common.tool.getElementByID("friendArea")
};

let selectedMenu = doms.conversationMenu;
let selectedArea = doms.conversationArea;

const changeMenu=(menu,area)=>{
    selectedMenu.className = "";
    selectedArea.style.display = "none";

    area.style.display = "block";
    menu.className = "selected";
    selectedMenu = menu;
    selectedArea = area;
}
Common.tool.addHandle(doms.conversationMenu,"click",()=>{
    changeMenu(doms.conversationMenu,doms.conversationArea)
})

Common.tool.addHandle(doms.groupMenu,"click",()=>{
    changeMenu(doms.groupMenu,doms.groupArea)
})

Common.tool.addHandle(doms.friendMenu,"click",()=>{
    Friend.initData();
    changeMenu(doms.friendMenu,doms.friendArea)
})

Common.tool.addHandle(doms.blacklistMenu,"click",()=>{
    changeMenu(doms.blacklistMenu,doms.blacklistArea)
})
Common.tool.addHandle(doms.userAvatar,"click",()=>{
    new EditMyWin().create();
})


const updateAvatar =(avatar)=>{
    doms.userAvatar.src = Common.tool.getAvatar(avatar);
}

const openLoginWin = function(){
    new LoginWin().create();
};




export default {
    updateAvatar:updateAvatar,
    openLoginWin:openLoginWin
};
